using System.Collections.Generic;
using System.Text;
using System.Web.Mvc;

namespace FwkLight.Web.UserSession
{
  public interface IDisplaySuccessMessages
  {
    ViewContext ViewContext { set; }
    TempDataDictionary TempData { set; }
    string Display ( );
  }


  public class DisplaySuccessMessages : IDisplaySuccessMessages
  {
    private readonly IBaseUserSession _userSession;
    private ViewContext _viewContext;

    public DisplaySuccessMessages ( IBaseUserSession userSession )
    {
      _userSession = userSession;
    }

    public ViewContext ViewContext
    {
      set { _viewContext = value; }
    }

    public TempDataDictionary TempData
    {
      set { _userSession.TempData = value; }
    }

    public string Display ( )
    {
      var errorHtml = new StringBuilder();
      IList<FlashMessage> messages = _userSession.PopSuccessMessages();
      if (messages.Count == 0) return "";

      errorHtml.Append(@"<p class='mesajSuccesform'>");


      foreach (FlashMessage message in messages)
      {
        errorHtml.AppendFormat(@"<span>{0}</span><br/>", message.Message);
      }

      errorHtml.Append("</p>");

      return errorHtml.ToString();
    }

  }
}